package com.zmj.sy.mom.srv.aps.controller;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmj.sy.mom.srv.aps.bean.dto.reportErp.ReportErpLogQureyDto;
import com.zmj.sy.mom.srv.aps.bean.dto.reportErp.ReportErpLogUpdateDto;
import com.zmj.sy.mom.srv.aps.bean.vo.base.Result;
import com.zmj.sy.mom.srv.aps.bean.vo.reportErp.SysReportErpLogVo;
import com.zmj.sy.mom.srv.aps.bean.vo.reportErp.TbThirdReportErpLogVo;
import com.zmj.sy.mom.srv.aps.service.ReportErpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RequiredArgsConstructor
@Api(tags = "回传erp")
@RestController
@RequestMapping("/completeReport")
public class ReportErpController {
    private final ReportErpService reportErpService;
    /**
     * @Description: 报工记录变更
     *
     * @author: hejiahui
     * @since: 2023/10/10 10:14
     */
    @ApiOperation(value = "1.0 报工记录变更", notes = "@作者  hejiahui   @操作时间 2023年10月10日10:14:31")
    @PostMapping(value = "/changeReportData")
    public Result changeReportData(@ApiParam(value = "开始时间") @RequestParam(name = "startTime",required = false)String startTime,
                                   @ApiParam(value = "结束时间") @RequestParam(name = "endTime",required = false)String endTime) {
        if (StringUtils.isBlank(startTime)) {
            startTime = DateUtil.date().offset(DateField.DAY_OF_MONTH,-7).toString();
        }
        if (StringUtils.isBlank(endTime)) {
            endTime = DateUtil.date().toString();
        }
        reportErpService.changeReportData(startTime,endTime);
        return Result.success("变更成功！");
    }
    /**
     * @Description: 根据分拣生成前序工序
     *
     * @author: hejiahui
     * @since: 2023/10/10 10:14
     */
    @ApiOperation(value = "1.0 根据分拣生成前序工序", notes = "@作者  hejiahui   @操作时间 2023年10月10日10:14:31")
    @PostMapping(value = "/buildBeforePhase")
    public Result buildBeforePhase(@ApiParam(value = "constructNo") @RequestParam(name = "constructNo",required = false) String constructNo) {
        reportErpService.buildBeforePhase(constructNo);
        return Result.success("变更成功！");
    }
    /**
     * @Description: 手动调用回传
     *
     * @author: hejiahui
     * @since: 2023/10/10 10:14
     */
    @ApiOperation(value = "1.1 手动调用回传", notes = "@作者  hejiahui   @操作时间 2023年10月10日10:14:31")
    @PostMapping(value = "/reportErpDate")
    public Result reportErpDate(@RequestBody List<Integer> ids) {
        reportErpService.rereportErpDate(ids);
        return Result.success("回传成功！");
    }

    /**
     * 分页查询
     *
     * @param reportErpLogQureyDto 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "分页查询", notes = "@作者  hejiahui   @操作时间  2024-10-14 15:06:41")
    @GetMapping("/getReportErpLogpage")
    public Result<IPage<SysReportErpLogVo>> getReportErpLogpage(ReportErpLogQureyDto reportErpLogQureyDto) {
        return Result.success(reportErpService.getReportErpLogpage(reportErpLogQureyDto));
    }
    /**
     * 更新数据
     *
     * @return 编辑结果
     */
    @ApiOperation(value = "编辑数据", notes = "@作者  hejiahui   @操作时间  2024-10-14 15:06:41")
    @PutMapping("/reportErpLogUpdate")
    public Result reportErpLogUpdate(@RequestBody ReportErpLogUpdateDto dto) {
        reportErpService.reportErpLogUpdate(dto);
        return Result.success();
    }
    /**
     * 删除数据
     *
     * @param ids 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "删除数据", notes = "@作者  hejiahui   @操作时间  2024-10-14 15:06:41")
    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestBody List<Integer> ids) {
        for (Integer id : ids) {
            reportErpService.deleteById(id);
        }
        return Result.success();
    }
    /**
     * @Description: 自动生成缺失的预处理记录
     *
     * @author: hejiahui
     * @since: 2025/3/15 8:28
     */
    @ApiOperation(value = "自动生成缺失的预处理记录", notes = "@作者  hejiahui   @操作时间 2023年10月10日10:14:31")
    @PostMapping(value = "/generateYcReport")
    public Result generateYcReport(@ApiParam(value = "constructNo") @RequestParam(name = "constructNo",required = false) String constructNo) {
        reportErpService.generateYcReport(constructNo);
        return Result.success("回传成功！");
    }
}
